#ifndef Model_H
#define Model_H
#include <qgl.h>
#include <QVector>
#include "glm/glm.hpp"
#include <QDataStream>



class Model
{
	friend QDataStream & operator>> (QDataStream & inStream, Model & model);
	friend QDataStream & operator<< (QDataStream & outStream, Model & model);

public:

	struct BoundingBox
	{
		glm::vec3 minPoint;
		glm::vec3 maxPoint;
	};

	Model ();
	Model (int vertexCount);
	~Model ();

	const QVector< glm::vec3 > & getVertices () const;
	const QVector< glm::vec3 > & getNormals ();
	const QVector< glm::vec2 > & getTexCoords () const;
	const QVector< glm::uvec3 > & getFaces () const;

	void addVertex (const glm::vec3 & vertex);
	void addVertex (const glm::vec3 & vertex, const glm::vec2 &texCoord);
	void setVertex (int index, const glm::vec3 & vertex);
	void addTexCoords (const glm::vec2 & texCoord);
	void setTexCoord (int index, const glm::vec2 & texCoord);
	void addFace (const glm::uvec3 & face);
	void setFace (int index, const glm::uvec3 & face);
	void clearFace ();

	int getVertexCount () const;
	int getFaceCount () const;

	void update ();
	void calcNormals ();
	BoundingBox getBoundingBox () const;


private:

	QVector< glm::vec3 > _vertices;
	QVector< glm::vec3 > _normals;
	QVector< glm::vec2 > _texCoords;
	QVector< glm::uvec3 > _faces;
	bool _needUpdate;

};


QDataStream & operator>> (QDataStream & inStream, Model & model);

QDataStream & operator<< (QDataStream & outStream, Model & model);

#endif // Model_H
